package main

import (
	"fmt"
	"law-api-master/cm"
	"law-api-master/cmd/flags"
	"law-api-master/routers"
	"net/http"


)

func root() string {
	return "welcome to visit SZU_Blockchain_Research Center"
}

func main() {
	flags.SetupLog()
	//set config about picoChain visit
	config := flags.ReadConfig()
	chain := cm.NewClientManager(config)

	//register all routers
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, root())
	})

	http.Handle("/api/add/address", routers.NewKeyHandler(chain))
	http.Handle("/api/upload/chain", routers.NewChainHandler(chain))
	http.Handle("/api/verify/chain", routers.NewVerifyHandler(chain))
	http.Handle("/api/charge/chain", routers.NewChargeHandler(chain))

	//register http port
	//第一个参数监听的端口”：8080“
	http.ListenAndServe(config.ListenAddr, nil)
}
